do (angular) ->
  angular.module 'tini', [
    'ngRoute'
  ]
  .config ($routeProvider, $httpProvider) ->

    #　对存档类页面的路由
    tplPostList = 'partial/posts.html'
    for type in [
      'category'
      'tag'
      'archive'
    ]
      $routeProvider
      .when "/#{type}/:#{type}",
        controller: type
        templateUrl: tplPostList
      .when "/#{type}/:#{type}/page/:page",
        controller: type
        templateUrl: tplPostList

    $routeProvider

    # 首页
    .when '/',
      controller: 'home'
      templateUrl: tplPostList

    # 首页分页
    .when '/page/:page',
      controller: 'home'
      templateUrl: tplPostList

    # 文章
    .otherwise
        controller: 'post'
        templateUrl: 'partial/post.html'

    # 默认开启 http 请求缓存
    $httpProvider.defaults.cache = true

  .run ($rootScope, $location) ->

    $rootScope.global = {}

    $rootScope.$on '$routeChangeSuccess', ->
      $rootScope.global.path = $location.path()
